//
//  HWAssetsViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/10/28.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWAssetsViewController.h"
#import "HWSetUpZhongXingTableViewCell.h"
#import "HWMyChangeduihuaViewController.h"
#import "HWMyVouchersViewController.h"
#import "HWMyBagsLiBaoViewController.h" //  我的礼包
#import "HWIntegralMallshopViewController.h"
#import "HWMyCurrencyViewController.h" // 我的绑币
#import "HWWebViewTopUpController.h"




@interface HWAssetsViewController ()<UITableViewDataSource,UITableViewDelegate,JXSegmentedListContainerViewListDelegate>


@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) NSArray *arr1;
@property(strong,nonatomic) NSArray *arr2;
@property(strong,nonatomic) NSArray *title1Arr;
@property(strong,nonatomic) NSArray *title2Arr;
@property(strong,nonatomic) NSDictionary *dataDic;

@property(strong,nonatomic)NSMutableArray *data1MuArr;
@property(strong,nonatomic)NSMutableArray *data2MuArr;





@end

@implementation HWAssetsViewController

-(UITableView *)mainaTableVie {

    if  (_mainaTableVie == nil) {

        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        _mainaTableVie.backgroundColor = RGB(247, 247, 247);
        
    }
    return   _mainaTableVie ;

}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (self.showNav == YES) {
        self.navigationController.navigationBarHidden = NO;
    }

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self navigationView];
    [self setupUI];
    
    [self fasonghuodongfuli];
    
    
    
    
}
- (UIView *)listView{
    return  self.view;
}

//发送网路请求
- (void)fasonghuodongfuli {
    
    
    
      
     self.data1MuArr = [[NSMutableArray alloc]init];
     self.data2MuArr = [[NSMutableArray alloc]init];
             NSString *userID = [HWLocallyStoredData getLoginUserID];
            NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
            NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
            NSString *signMD5 = [WMUtil md5HexDigest:sign];
            NSDictionary *parametes = @{
                                       @"ct" :  @"app",
                                       @"ac" : @"myassets",
                                       @"ios" : @"1",
                                       @"Version" : @"3.0",
                                       @"member_id":[HWLocallyStoredData getCode],
                                       @"uid":userID,
                                       @"t":tStr,
                                       @"sign":signMD5,
                                       @"language":[HWjianzhiduiObject returnLanguageAcquisition],
                                      
                                       };
      
      
           
       //    [MBProgressHUD show:@"正在绑定邮箱"];
    
    
      [HWWebUtils do4GetWithParameters:parametes hiddenparameterStr:HW_myassets progress:nil success:^(id  _Nullable response) {
        
                   NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                    //   [MBProgressHUD hideHUD];
                       
                       
                       if ([codeStr intValue] == 1) {
                           
                    
                        self.dataDic = response[@"data"];
                    
                           
                           [self.data1MuArr addObject:self.dataDic[@"coin"]];
                            [self.data1MuArr addObject:self.dataDic[@"coupon"]];
                            [self.data1MuArr addObject:self.dataDic[@"lb"]];
                           [self.data1MuArr addObject:self.dataDic[@"bind"]];
                           
                      
                          [self.data2MuArr addObject:self.dataDic[@"points"]];
                          [self.data2MuArr addObject:self.dataDic[@"order"]];
                           
                           
                          [self.mainaTableVie reloadData];

                       } else {
                        
                            [MBProgressHUD  showSuccess:response[@"message"]];
                           
                       }
                       NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
        
             [MBProgressHUD  showError:@"查询失败"];
        
    }];
    
    
           
//           [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
//               
//             
//               NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//            //   [MBProgressHUD hideHUD];
//               
//               
//               if ([codeStr intValue] == 1) {
//                   
//            
//                self.dataDic = response[@"data"];
//            
//                   
//                   [self.data1MuArr addObject:self.dataDic[@"coin"]];
//                    [self.data1MuArr addObject:self.dataDic[@"coupon"]];
//                    [self.data1MuArr addObject:self.dataDic[@"lb"]];
//                   [self.data1MuArr addObject:self.dataDic[@"bind"]];
//                   
//              
//                  [self.data2MuArr addObject:self.dataDic[@"points"]];
//                  [self.data2MuArr addObject:self.dataDic[@"order"]];
//                   
//                   
//                  [self.mainaTableVie reloadData];
//
//               } else {
//                
//                    [MBProgressHUD  showSuccess:response[@"message"]];
//                   
//               }
//               NSLog(@"%@",response);
//               
//               
//           } failure:^(NSString *error) {
//
//               [MBProgressHUD  showError:@"查询失败"];
//               
//              
//           }];
//    
//    
    
    
    
    
}











- (void)navigationView {
    
    self.navigationItem.title = @"我的资产";
    self.navigationItem.title = [HWjianzhiduiObject keylocalization:@"我的资产"];
    
    
    
    self.arr1 = @[@"pingtaibi",@"daijingjuan",@"libao",@"bangbicheng"];
    self.arr2 = @[@"jifenjifen",@"duihuanshangping"];
//    self.title1Arr = @[@"平台币",@"代金券",@"礼包",@"绑币"];
//    self.title2Arr = @[@"积分",@"兑换过的商品"];
//

    self.title1Arr = @[[HWjianzhiduiObject keylocalization:@"平台币"],[HWjianzhiduiObject keylocalization:@"代金券"],[HWjianzhiduiObject keylocalization:@"礼包"],[HWjianzhiduiObject keylocalization:@"绑币"]];
    self.title2Arr = @[[HWjianzhiduiObject keylocalization:@"积分"],[HWjianzhiduiObject keylocalization:@"兑换过的商品"]];
    
    
}



- (void)setupUI {
    
    self.view.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.mainaTableVie];
}




- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    
    return  2;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    if (section == 0 ) {
        
        return  self.arr1.count;
         
    } else {
        
        return  self.arr2.count;
        
        
    }
     
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString *cellID = @"cellID";
    HWSetUpZhongXingTableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
    
    
    if (!cell) {
        cell =  [[NSBundle mainBundle]loadNibNamed:@"HWSetUpZhongXingTableViewCell" owner:nil options:nil].firstObject;
    
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    if (indexPath.section == 0 ) {
        
        cell.tubiao.image = [UIImage imageNamed:self.arr1[indexPath.row]];
        cell.miaoshuLabel.text = [NSString stringWithFormat:@"%@",self.title1Arr[indexPath.row]];
             
    } else {
        
        cell.tubiao.image = [UIImage imageNamed:self.arr2[indexPath.row]];
        cell.miaoshuLabel.text = [NSString stringWithFormat:@"%@",self.title2Arr[indexPath.row]];
            
    }
    
    
    
    if ( indexPath.row ==  0 ) {
        cell.shangView.hidden = YES;
        
    } else {
        
         cell.shangView.hidden = NO;
        
    }

    
    
    
    if (indexPath.section == 0 && indexPath.row == 3) {
         cell.xiaView.hidden = YES;
    } else if (indexPath.row == 1 && indexPath.section == 1) {
        
          cell.xiaView.hidden = YES;
        
    } else {
        
         cell.xiaView.hidden = NO;
    }
    
    cell.rightLabel.hidden = YES;
     
    
    
 
    if (self.dataDic != nil ) {
         cell.rightLabel.hidden = NO;
        if (indexPath.section == 0) {
            
             cell.rightLabel.text = self.data1MuArr[indexPath.row];
             
             
         } else {
             
               cell.rightLabel.text = self.data2MuArr[indexPath.row];
             
             
             
         }
         
        
    }
    
    
    if(indexPath.row == 0 ) {
         
        cell.rightLabel.frame =   CGRectMake(kScreenW-40-10-280,0 , 280, 54);
        
        cell.righetjiantouImageView.hidden = YES;
        
        
    } else {
        
        
        cell.rightLabel.frame =   CGRectMake(kScreenW-40-30-280,0 , 280, 54);
        
            cell.righetjiantouImageView.hidden = NO;
        
    }
    
    
 
  
    
    
    return  cell;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return  55;
    
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    
    return  10;
    
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    
    
    return 1;
    
    

    
    
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    
    UIView *view1 = [[UIView alloc]init];
    view1.backgroundColor = RGB(247, 247, 247);
    return view1;
    
    
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
       UIView *view2 = [[UIView alloc]init];
       view2.backgroundColor = RGB(247, 247, 247);
       return view2;
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
     
    
    if (indexPath.section == 0 ) {
        
        
        if (indexPath.row == 0 ) {
            
            HWWebViewTopUpController  *web = [[HWWebViewTopUpController alloc]init];
                  [self.navigationController pushViewController:web animated:YES];
                          
                      
            
            
        } else if (indexPath.row == 1) {
            
            
            HWMyVouchersViewController *myvouchers =  [[HWMyVouchersViewController alloc]init];
            [self.navigationController pushViewController:myvouchers animated:YES];
    
            
        } else if (indexPath.row == 2) {
            
            HWMyBagsLiBaoViewController *libao = [[HWMyBagsLiBaoViewController alloc]init];
           [self.navigationController  pushViewController:libao animated:YES];
            
           
            
            
        } else if (indexPath.row == 3)  {
            
            HWMyCurrencyViewController  *bangdi  = [[HWMyCurrencyViewController alloc]init];
            [self.navigationController pushViewController:bangdi animated:YES];
            
            
            
            
            
        }
        
         
    } else if (indexPath.section == 1) {
        
        if (indexPath.row == 0 ) {
            
            HWIntegralMallshopViewController *intat = [[HWIntegralMallshopViewController alloc]init];
            [self.navigationController  pushViewController:intat animated:YES];
            
            
            
             
        } else if (indexPath.row == 1) {
            
            
            HWMyChangeduihuaViewController * Changedui = [[HWMyChangeduihuaViewController  alloc]init];
            [self.navigationController pushViewController:Changedui animated:YES];
            
        }
        
        
    }
    
   
    
}
 






@end


//// 设置UI
//- (void)setupUI  {
//
//    self.view.backgroundColor  = [UIColor redColor];
//
//
//    self.arr1 = @[@"pingtaibi",@"daijingjuan",@"libao",@"bangbicheng"];
//    self.arr2 = @[@"jifenjifen",@"duihuanshangping"];
//
//
//
//
//}
//



